//
//  NSMutableAttributedString+String.m
//  WHPersonalData
//
//  Created by mac on 2018/10/16.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "NSMutableAttributedString+String.h"

@implementation NSMutableAttributedString (String)

/*
 方法名:  改变字体的颜色
 @param  attString                  要改变字体颜色的字符串
 @param  lenght                     从零开始的长度
 @param  color                      颜色
 @return NSMutableAttributedString
 */

+(NSMutableAttributedString *)setAttributeWithString:(NSString *)attString withLenght:(int)lenght withColor:(UIColor*)color
{
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:attString];
    NSRange range = NSMakeRange(0,lenght);
    [AttributedStr addAttribute:NSForegroundColorAttributeName
                          value:color
                          range:range];
    return AttributedStr;
}

/*
 方法名:  改变字体的颜色
 @param  attString                  要改变字体颜色的字符串
 @param  range                      范围
 @param  color                      颜色
 @return NSMutableAttributedString
 */
+(NSMutableAttributedString *)setAttributeWithString:(NSString *)attString withRange:(NSRange)range withColor:(UIColor*)color
{
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:attString];
    [AttributedStr addAttribute:NSForegroundColorAttributeName
                          value:color
                          range:range];
    return AttributedStr;
}

/*
 方法名:  改变字体的大小
 @param  needText                   要改变字体颜色的字符串
 @param  lenght                     长度
 @return NSMutableAttributedString
 */

+(NSMutableAttributedString*)changeLabelWithText:(NSString*)needText withLenght:(NSInteger)lenght
{
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:needText];
    UIFont *font = [UIFont systemFontOfSize:16];
    [attrString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0,lenght)];
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(lenght,needText.length-lenght)];
    return attrString;
}

@end
